package com.bjtang.book.dto;

import java.time.LocalDateTime;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Null;

import org.hibernate.validator.constraints.Length;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.bjtang.book.entiy.ArticleBody;
import com.bjtang.book.entiy.ArticleHead;
import com.fasterxml.jackson.annotation.JsonFormat;

import lombok.Data;

@Data
public class ArticleDto {
	// 主键
	// @TableId(type = IdType.AUTO)
	private Long articleNumber;
	// 文章标题
	@Length(min = 0, max = 120)
	private String title;
	// 文章简介
	@Length(min = 0, max = 1000)
	private String summary;
	// 文章题图url
	@Length(min = 0, max = 1000)
	private String pictureUrl;
	// 相关商品
	private Long bookNumber;
	// 正文
	private String content;
	// 文章访问量
	@Null
	private Long traffic;
	// 点赞量
	@Null
	private Long upNumber;
	// 点踩量
	@Null
	private Long downNumber;
	// 推荐次数
	@Null
	private Long recommendNumber;
	// 创建者ID
	@Null
	private Long founder;
	// 创建者姓名
	@Null
	private String founderName;
	// 创建时间
	@Null
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private LocalDateTime creationTime;
	// 文章状态
	@Max(value = 1)
	@Min(value = 0)
	private Integer status;
	// 删除标志
	// 逻辑删除标识(0.未删除,1.已删除)
	@TableLogic
	@TableField(select = false) // 查询结果不显示
	private Integer deleted;

	// 更新者Id
	@Null
	private Long updateBy;
	// 更新时间
	@Null
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private LocalDateTime updateTime;

	public ArticleHead getHead() {
		ArticleHead articleHead = new ArticleHead();
		articleHead.setArticleNumber(this.articleNumber);
		articleHead.setBookNumber(this.bookNumber);
		articleHead.setCreationTime(this.creationTime);
		articleHead.setDeleted(this.deleted);
		articleHead.setDownNumber(this.downNumber);
		articleHead.setFounder(this.founder);
		articleHead.setPictureUrl(this.pictureUrl);
		articleHead.setRecommendNumber(this.recommendNumber);
		articleHead.setStatus(this.status);
		articleHead.setSummary(this.summary);
		articleHead.setTitle(this.title);
		articleHead.setTraffic(this.traffic);
		articleHead.setUpNumber(this.upNumber);
		return articleHead;
	}

	public ArticleBody getBody() {
		ArticleBody articleBody = new ArticleBody();
		articleBody.setArticleNumber(this.articleNumber);
		articleBody.setContent(this.content);
		articleBody.setUpdateBy(this.updateBy);
		articleBody.setUpdateTime(this.updateTime);
		return articleBody;
	}

	public void setHead(ArticleHead articleHead) {
		this.articleNumber = articleHead.getArticleNumber();
		this.bookNumber = articleHead.getBookNumber();
		this.creationTime = articleHead.getCreationTime();
		this.deleted = articleHead.getDeleted();
		this.downNumber = articleHead.getDownNumber();
		this.founder = articleHead.getFounder();
		this.pictureUrl = articleHead.getPictureUrl();
		this.recommendNumber = articleHead.getRecommendNumber();
		this.status = articleHead.getStatus();
		this.summary = articleHead.getSummary();
		this.title = articleHead.getTitle();
		this.traffic = articleHead.getTraffic();
		this.upNumber = articleHead.getUpNumber();
	}

	public void setBody(ArticleBody articleBody) {
		this.articleNumber = articleBody.getArticleNumber();
		this.content = articleBody.getContent();
		this.updateBy = articleBody.getUpdateBy();
		this.updateTime = articleBody.getUpdateTime();
	}
}
